#region [file: ConvenioDAL.cs, author: Lucas Bittencourt]
// File:    ConvenioDAL.cs
// Author:  Lucas Bittencourt
// Created: quarta-feira, 16 de novembro de 2011 18:32:59
// Purpose: Defines dao implementation class for class Convenio
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using DA_OOMModel;
using DA_OOMModelIDAL;

namespace DA_OOMNHibernateDAL
{
   /// <summary>
   /// Class that implements methods of IConvenioDAL interface
   /// </summary>
   public class ConvenioDAL : NHibernateDALBase,  IConvenioDAL 
   {
      #region CRUD methods
      /// <summary>
      /// Get all instances of Convenio
      /// </summary>     
      public List<Convenio> GetConvenioList()
      {
         return ConvertToGenericList(base.LoadAll(typeof(Convenio)));
      }
      
      /// <summary>
      /// Get the instances of Convenio from index firstResult to index maxResult
      /// </summary>
      public List<Convenio> GetConvenioList(int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.LoadAll(typeof(Convenio), firstResult, maxResult));
      }

      /// <summary>
      /// Load the instance of Convenio according its primary key instance.
      /// </summary>
      public Convenio Load(ConvenioPK convenioPK)
      {
         IList cs = new ArrayList();
         string[] paramNames = new string[] { "CvnIdConvenio" };
         object[] values = new object[] { convenioPK.CvnIdConvenio };
         for (int i = 0; i < paramNames.Length; i++)
             cs.Add(Expression.Eq(paramNames[i], values[i]));

         IList list = base.FindByCriterions(typeof(Convenio), cs);
         return (((list != null) && (list.Count > 0)) ? (Convenio)list[0] : null);
      }

      /// <summary>
      /// Query the instances of Convenio according its example instance.
      /// </summary>
      public List<Convenio> QueryByExample(Convenio convenio)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Convenio), convenio));
      }

      /// <summary>
      /// Query the instances of Convenio according its example instance from index firstResult to index maxResult
      /// </summary>
      public List<Convenio> QueryByExample(Convenio convenio, int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Convenio), convenio, firstResult, maxResult));
      }
      
      /// <summary>
      /// Insert the instances of Convenio
      /// </summary>
      public void Insert(Convenio convenioObject)
      {
         base.Save(convenioObject);
      }
      
      /// <summary>
      /// Update the instances of Convenio
      /// </summary>
      public void Update(Convenio convenioObject)
      {
         base.Update(convenioObject);
      }
      
      /// <summary>
      /// Delete the instances of Convenio
      /// </summary>
      public void Delete(Convenio convenioObject)
      {
         base.Delete(convenioObject);
      }
      #endregion
      
   
      /// <summary>
      /// Find the instances of Convenio according to its attribute cvnCdCedente
      /// </summary>
      public List<Convenio> FindByCvnCdCedente(string cvnCdCedente) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("CvnCdCedente", cvnCdCedente));
         return ConvertToGenericList(base.FindByCriterions(typeof(Convenio), cs));
      }
      
      /// <summary>
      /// Find the instances of Convenio according to its attribute cvnCdCedente, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Convenio> FindByCvnCdCedente(string cvnCdCedente, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("CvnCdCedente", cvnCdCedente));
         return ConvertToGenericList(base.FindByCriterions(typeof(Convenio), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Convenio according to its attribute cvnNuProximoNossoNumero
      /// </summary>
      public List<Convenio> FindByCvnNuProximoNossoNumero(string cvnNuProximoNossoNumero) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("CvnNuProximoNossoNumero", cvnNuProximoNossoNumero));
         return ConvertToGenericList(base.FindByCriterions(typeof(Convenio), cs));
      }
      
      /// <summary>
      /// Find the instances of Convenio according to its attribute cvnNuProximoNossoNumero, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Convenio> FindByCvnNuProximoNossoNumero(string cvnNuProximoNossoNumero, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("CvnNuProximoNossoNumero", cvnNuProximoNossoNumero));
         return ConvertToGenericList(base.FindByCriterions(typeof(Convenio), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Convenio according to its attribute cvnCdVariacao
      /// </summary>
      public List<Convenio> FindByCvnCdVariacao(string cvnCdVariacao) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("CvnCdVariacao", cvnCdVariacao));
         return ConvertToGenericList(base.FindByCriterions(typeof(Convenio), cs));
      }
      
      /// <summary>
      /// Find the instances of Convenio according to its attribute cvnCdVariacao, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Convenio> FindByCvnCdVariacao(string cvnCdVariacao, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("CvnCdVariacao", cvnCdVariacao));
         return ConvertToGenericList(base.FindByCriterions(typeof(Convenio), cs, firstResult, maxResult));
      }
      
      /// <summary>
      /// Find <Code>Convenio</Code> instances by ContaBancaria
      /// </summary>
      /// <param name="contaBancaria"/>
      /// <returns>Convenio instance list</returns>
      public List<Convenio> FindByContaBancaria(ContaBancaria contaBancaria)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("ContaBancaria", contaBancaria));
         return ConvertToGenericList(base.FindByCriterions(typeof(ContaBancaria), cs));
      }
      
      /// <summary>
      /// Find <Code>Convenio</Code> instances  instances in range firstResult, maxResult by ContaBancaria
      /// </summary>
      /// <param name="contaBancaria"/>
      /// <param name="firstResult">first result to return</param>
      /// <param name="maxResult">max result to return</param>
      /// <returns>Convenio instance list</returns>
      public List<Convenio> FindByContaBancaria(ContaBancaria contaBancaria, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("ContaBancaria", contaBancaria));
         return ConvertToGenericList(base.FindByCriterions(typeof(ContaBancaria), cs, firstResult, maxResult));
      }

      /// <summary>
      /// Convert the IList to the generic List instance.
      /// </summary>
      private List<Convenio> ConvertToGenericList(IList convenios)
      {
         List<Convenio> convenioList = new List<Convenio>();
         foreach (Convenio convenio in convenios)
         {
             convenioList.Add(convenio);
         }
         return convenioList;
      }      
   }
}